<!DOCTYPE html>
<html>
<head>
<head/>
	<div th:include="base-libs-easyui :: base-libs-easyui" />
<title>角色列表</title>
<style type="text/css">
</style>
</head>
<script th:inline="javascript">
	/**读取request中的初始化数据*/
	var roleScope = [[${roleScope}]];
</script>
<script type="text/javascript">
$(function() {
 	initView();
 	$("#btnQuery").trigger("click");
});

function queryForm() {
    $("#dgForm").datagrid({url: contextRoot + "/role/queryPageRole.service"});
}

function initView()
{
	$("#dgForm").datagrid({
		idField : "ROLEID",
		striped : true,
        fitColumns : true,
        fit : true,
        border : false,
        rownumbers: true,
        singleSelect: true,
		toolbar : "#tb",
        pagination: true,
		columns : [[
			{
				field : "ROLEID",
				title : "角色ID"
				,width: 4
			},
			{
				field : "ROLENAME",
				title : "角色名称"
                ,width: 4
			},
			{
				field : "TYPE_DESCRIBE",
				title : "角色权限范围"
            	,width: 10
                ,formatter : function(value, row, index){
                	return '<span title="' + value + '">' + value + '</span>';
                }
			},
			{
				field : "CZ",
				title : "操作"
            	,width: 2
				,formatter : function(value, row, index){
				    var tableToolBar = $("#tableToolBar").html();
				    if(!StringUtils.isEmpty(row["SUPER"])){
                        var _this = $(tableToolBar);
                        $(_this).find("a[action='delete']").remove();
                        tableToolBar = _this.prop('outerHTML');
					}
					return tableToolBar.replace(/ROLEID/g, row["ROLEID"]);
				}
			}
		]]
		,onBeforeLoad: function(queryParams) {
            var url = $(this).datagrid("options")["url"];
			/*URL不等空时再发送请求*/
            if (!StringUtils.isEmpty(url)) {
                queryParams["pageSize"] = queryParams["rows"];
                queryParams["pageNumber"] = queryParams["page"];
                queryParams["ROLENAME"] = $("#JSMC").val();
                return true;
            }else{
                return false;
			}
        }
	});

	$("body").on("click", ".tableToolBarBtn", function(){
        var action = $(this).attr("action");
        var roleId = $(this).attr("id");
        $("#dgForm").datagrid("selectRecord", roleId);
        if("update" == action){
            updateRole(roleId);
        }else if("delete" == action){
            deleteRole(roleId);
        }
	})
}

/**更新角色*/
function updateRole(roleId){
    var role = $("#dgForm").datagrid("getSelected");
    StoreCache.setCache("cache_role", role);
    location = "manager.html?ROLEID="+roleId;
}

/*删除角色*/
function deleteRole(roleId){
    $.QuickAlert.alertConfirm({content:"删除角色可能导致相关人员不能登录或操作功能，是否删除记录", callback: function(){
        var url = contextRoot + "role/delete";
        $.QuickRemote.AjaxJson(url, function(result){
            if(result["state"])
            {
                $.QuickAlert.alertNormal("删除成功");
                $("#btnQuery").trigger("click");
            }
            else
            {
                $.QuickAlert.alertNormal("删除失败");
            }
        }, {ROLEID: roleId})
    }})
}

/**查询按钮点击回调*/
function btnQueryHandler() {
	queryForm();
}

function btnAddHandler(){
	location = "manager.html";
}
</script>
<body class="easyui-layout">
<div region="north" style="height: 41px; border: none; overflow: hidden; background-color: #f9f9f9;">
	<div style="width: 100%; height: 100%; margin-left: 30px">
		<h3 style="line-height: 41px; margin: 0px; font-size: 18px;font-weight: bold;">角色列表</h3>
	</div>
</div>
<div region="center">
	<div id="tb" style="padding:8px 20px;">
		<label>角色名称:</label><input id="JSMC" style="width: 200px">
		<button id="btnQuery" class="btn btn-default" type="button" onclick="btnQueryHandler()">查询</button>
		<button id="btnAdd" class="btn btn-default" type="button" onclick="btnAddHandler()">新增</button>
	</div>
	<table id="dgForm"></table>
</div>
<script type="text/html" id="tableToolBar">
	<div>
		<a class="tableToolBarBtn" action="update" id=ROLEID href="javascript:void(0)" title="修改" style="color: #00c297;">修改</a>
		<a class="tableToolBarBtn" action="delete" id=ROLEID href="javascript:void(0)" title="删除" style="color: #00c297;">删除</a>
	</div>
</script>
</body>
</html>


















































